﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZCUIManager;

namespace ZCTouchDrawBoard
{
    /// <summary>
    /// 画板的UI, 选项卡
    /// </summary>
    public class TouchDrawingView : UIBaseView
    {
        #region PrivateFiled
        /// <summary>
        /// 画笔选项卡
        /// </summary>
        private Button m_ButtonTabPaintPanel;

        /// <summary>
        /// 画布选项卡
        /// </summary>
        private Button m_ButtonTabPaperPanel;

        /// <summary>
        /// 内容
        /// </summary>
        private RectTransform m_RectTransformContent;

        /// <summary>
        /// 图纸面板
        /// </summary>
        private PaperPanel m_PaperPanel;

        /// <summary>
        /// 笔面板
        /// </summary>
        private PaintPanel m_PaintPanel;
        #endregion

        #region PublicMethod
        /// <summary>
        /// 画板view
        /// </summary>
        public PaperPanel PaperPanel => m_PaperPanel;

        /// <summary>
        /// 画笔view
        /// </summary>
        public PaintPanel PaintPanel => m_PaintPanel;

        /// <summary>
        /// 图纸
        /// </summary>
        public BasePaperView SelectPaper => m_PaperPanel.SelectPaperView;

        /// <summary>
        /// 画笔
        /// </summary>
        public BasePaint SelectPaint => m_PaintPanel.SelectPaint;
        #endregion

        #region OverrideMethod
        public override void Initialize(eUIType uiType, GameObject go)
        {
            base.Initialize(uiType, go);

            m_RectTransformContent = Find(m_RectTransform, "Content").GetComponent<RectTransform>();

            m_PaintPanel = UIManager.Instance.GetUIView<PaintPanel>(eUIType.PaintPanel);
            m_PaintPanel.SetParent(m_RectTransformContent);
            m_PaintPanel.TouchDrawingView = this;

            m_PaperPanel = UIManager.Instance.GetUIView<PaperPanel>(eUIType.PaperPanel);
            m_PaperPanel.SetParent(m_RectTransformContent);
            m_PaperPanel.TouchDrawingView = this;

            m_PaintPanel.Show();
            m_PaperPanel.Hide();

            m_ButtonTabPaintPanel = Find(m_RectTransform, "ButtonTabPaintPanel").GetComponent<Button>();
            m_ButtonTabPaperPanel = Find(m_RectTransform, "ButtonTabPaperPanel").GetComponent<Button>();
        }

        public override void InitializeListener()
        {
            base.InitializeListener();
            m_ButtonTabPaintPanel.onClick.AddListener(OnClickTabPaintPanel);
            m_ButtonTabPaperPanel.onClick.AddListener(OnClickTabPaperPanel);
        }

        public override void Uninitialize()
        {
            m_PaperPanel.Uninitialize();
            m_PaintPanel.Uninitialize();
        }
        #endregion

        #region Public Method
        public void RefreshPaintList(List<PaintAttribute> paintAttributes)
        {
            m_PaintPanel.RefreshPaintList(paintAttributes);
        }
        #endregion

        #region Listener
        private void OnClickTabPaintPanel()
        {
            m_PaintPanel.Show();
            m_PaperPanel.Hide();
        }

        private void OnClickTabPaperPanel()
        {
            m_PaintPanel.Hide();
            m_PaperPanel.Show();
        }
        #endregion
    }
}
